package com.sk.bilibili.view.diy.bottomDialog;

import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.sk.bilibili.R;
import com.sk.bilibili.adapter.simple.bottomDialog.CollectAdapter;
import com.sk.bilibili.bean.Favorites;
import com.sk.bilibili.callBack.FavoritesClickCallBack;
import com.sk.bilibili.model.diy.bottomDialog.CollectModel;

import java.util.List;

import me.shaohui.bottomdialog.BaseBottomDialog;

public class CollectBottomDialog extends BaseBottomDialog implements FavoritesClickCallBack {

    private CollectModel model=new CollectModel(this);
    private Integer videoSetId;

    public CollectBottomDialog(Integer videoSetId) {
        this.videoSetId = videoSetId;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.bottom_dialog_collect;
    }

    @Override
    public int getHeight() {
        return (int) (getContext().getResources().getDisplayMetrics().density*300+0.5f);
    }

    private TextView cancel;
    private ListView show;
    private CollectAdapter collectAdapter;

    @Override
    public void bindView(View v) {
        cancel=v.findViewById(R.id.tv_cancel);
        show=v.findViewById(R.id.lv_show);
        show.setDividerHeight(3);
        bindEvent();
        initData();
    }

    private void initData() {
        model.loadFavorites();
    }

    private void bindEvent() {
        cancel.setOnClickListener(v->dismiss());
        collectAdapter = new CollectAdapter(getContext(), this);
        show.setAdapter(collectAdapter);
    }

    @Override
    public void onFavoritesClick(Integer id) {
        model.addCollect(videoSetId,id);
    }

    public void loadFavoritesSuccess(List<Favorites> favorites) {
        collectAdapter.setData(favorites);
    }

    public void addCollectSuccess() {
        Toast.makeText(getContext(), "收藏成功", Toast.LENGTH_SHORT).show();
        dismiss();
    }

}